package user.code.controller;

import com.yq.light.commons.code.entity.CommonResult;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import user.code.service.UserService;

@CrossOrigin
@Controller
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/registerAccount")
    @ResponseBody
    public CommonResult registerAccount(com.sample.User user){
        log.info("registerAccount 参数 user:"+user);
        int result = userService.registerAcont(user);
        log.info("registerAccount result:"+result);
        if(result > 0){
            return new CommonResult(200,"注册成功",result);
        }
        return new CommonResult(200,"注册失败",result);
    }

    @RequestMapping("/loginNoToken")
    @ResponseBody
    public CommonResult loginNoToken(@RequestBody com.sample.User user){
        log.info("loginNoToken parameter--user:"+user);
        String result = null;
        result = userService.loginNoToken(user).toString();
        if(result!=null){
            return new CommonResult(200,"登录成功",result);
        }
        return new CommonResult(200,"登录失败",result);
    }
}
